package com.hqd.ch03.test.web.v32;


import com.hqd.ch03.v32.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor implements HandlerInterceptor {

    // 在请求处理前执行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("Pre-handle: " + request.getRequestURI());
        request.setAttribute("message", "Add Interceptor");
        return true;
    }

    // 在请求处理后，视图渲染前执行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("Post-handle: " + request.getRequestURI());
    }

    // 在请求完全处理完后执行
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
                                Exception ex) throws Exception {
        System.out.println("After completion: " + request.getRequestURI());
    }
}